/**
 * 注射器
 */
Injector = Widget.extend({
	ctor:function(parent){
		this._super();
		parent.addChild(this,20);
		this.setTag(TAG_INJECTOR);
		this.init();
	},
	init : function(){
		this.setVisible(false);
		this.setCascadeOpacityEnabled(true);
		
		//注射器1（针头）--body
		var body = new Button(this, 10, TAG_INJECTOR1, "#run/injector1.png",this.callback);
		body.setPosition(cc.p(620,150));
		body.setRotation(90);
		//注射器2（外壳）
		var injector2 = new Button(body, 15, TAG_INJECTOR2, "#run/injector2.png",this.callback);
		injector2.setPosition(cc.p(46,136));
		//注射器3（推）
		var injector3 = new Button(body, 11, TAG_INJECTOR3, "#run/injector3.png",this.callback,this);
		injector3.setPosition(cc.p(44,234));
		//红色1
		var red1 = new cc.Sprite("#run/red1.png");
		body.addChild(red1,8,TAG_RED1);
		red1.setPosition(cc.p(44,128));
		red1.setAnchorPoint(0.5, 0);
		red1.setScale(1, 3);
		//红色2
		var red2 = new cc.Sprite("#run/red2.png");
		body.addChild(red2,7);
		red2.setPosition(cc.p(43,127));
	},	
	callback:function(p){
		var action = gg.flow.flow.action;
		switch(p.getTag()){
		case TAG_INJECTOR1:
			if(action == ACTION_DO1){
				var rotate1 = cc.rotateTo(1,45);
				var move1 = cc.moveTo(1,cc.p(630,470));
				var spawn1 = cc.spawn(rotate1,move1);
				var rotate2 = cc.rotateTo(1,30);
				var move2 = cc.moveTo(1,cc.p(540,505));
				var spawn2 = cc.spawn(rotate2,move2);
				var rotate3 = cc.rotateTo(1,10);
				var move3 = cc.moveTo(1,cc.p(440,325));
				var spawn3 = cc.spawn(rotate3,move3);
				//回归原位置
				var rotate4 = cc.rotateTo(1,90);
				var move4 = cc.moveTo(1,cc.p(620,150));
				var spawn4 = cc.spawn(rotate4,move4);
				var seq = cc.sequence(spawn1,spawn2,spawn3,cc.delayTime(0.5),cc.callFunc(function() {
					//推推
					var tui = p.getChildByTag(TAG_INJECTOR3);
					tui.runAction(cc.moveBy(0.8, 0, -5));
					//注射器内的红墨水
					var injector_red = p.getChildByTag(TAG_RED1);
					injector_red.runAction(cc.scaleTo(0.8, 1, 2.6));
					//烧杯内的红墨水
					var beaker_red = new cc.Sprite("#run/moshui1.png");
					beaker_red.setScale(0.1,0.3);
					beaker_red.setPosition(cc.p(113,63));
					ll.run.getChildByTag(TAG_COLD_BODY).addChild(beaker_red,22);
					beaker_red.runAction(cc.sequence(cc.spawn(cc.moveTo(10, cc.p(172,108)),cc.scaleTo(10, 2.6,2))));
				}, this),cc.delayTime(1),spawn2,spawn1,spawn4,cc.delayTime(4),cc.callFunc(function() {
					gg.flow.next();
				}, this));
				p.runAction(seq);
			}else if(action == ACTION_DO2){
				var rotate1 = cc.rotateTo(1,0);
				var move1 = cc.moveTo(1,cc.p(710,470));
				var spawn1 = cc.spawn(rotate1,move1);
				var rotate2 = cc.rotateTo(1,-30);
				var move2 = cc.moveTo(1,cc.p(780,505));
				var spawn2 = cc.spawn(rotate2,move2);
				var rotate3 = cc.rotateTo(1,-10);
				var move3 = cc.moveTo(1,cc.p(865,325));
				var spawn3 = cc.spawn(rotate3,move3);
				//回归原位置
				var rotate4 = cc.rotateTo(1,90);
				var move4 = cc.moveTo(1,cc.p(620,150));
				var spawn4 = cc.spawn(rotate4,move4);
				var seq = cc.sequence(spawn1,spawn2,spawn3,cc.delayTime(0.5),cc.callFunc(function() {
					//推推
					var tui = p.getChildByTag(TAG_INJECTOR3);
					tui.runAction(cc.moveBy(0.8, 0, -5));
					//注射器内的红墨水
					var injector_red = p.getChildByTag(TAG_RED1);
					injector_red.runAction(cc.scaleTo(0.8, 1, 2.2));
					//烧杯内的红墨水
					var beaker_red = new cc.Sprite("#run/moshui2.png");
					beaker_red.setScale(0.1,0.1);
					beaker_red.setPosition(cc.p(203,60));
					ll.run.getChildByTag(TAG_HOT_BODY).addChild(beaker_red,22);
					beaker_red.runAction(cc.sequence(cc.spawn(cc.moveTo(10, cc.p(163,157)),cc.scaleTo(10, 2,1.8),cc.fadeTo(10, 150))));
				}, this),cc.delayTime(1),spawn2,spawn1,spawn4,cc.delayTime(12),cc.callFunc(function() {
					gg.flow.next();
//					this.removeFromParent(true);
				}, this));
				p.runAction(seq);
			}
			break;
		default:
			break;
		}
	}
});
